#!/bin/bash

#clean the data file
echo \#start >figure.dat


#run the simulation 10 times
# simulation_red w_p
simulation_red()
{ 
# $1 is the first parameter of simulation()
n1=3 #minithreshold
n2=9 #maxthreshold
n3=$1 #max_p value

for simulation_i in  1 2 3 4 5 6 7 8 9 10; do
	# ns red.tcl minithreshold seed maxthreshold w_q
	ns red.tcl $n1 $simulation_i $n2 $n3
done
}

#run the simulation
#for w_p_i in 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 ;
#for w_p_i in 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1;
for ((w_p_i= 1; w_p_i <= 80; w_p_i=w_p_i+ 1 )) 
do
	# simulation_red w_p
	simulation_red `echo "scale=6;$w_p_i/10000.0" | bc` >temp_data

	#store data in figure2.dat by following format
	# w_p delay throughput throughput/delay
	# w_p delay throughput throughput/delay
	# ...
	cat temp_data | awk 'BEGIN{w_q=0; delay=0; throughput=0} 
			{if ($1=="w_q"){w_q=$2}; 	
			if ($2=="delay"){delay=delay+$5};
 			if ($2=="throughput"){throughput=throughput+$5}} 
			END{print w_q, delay/10.0, throughput/10.0, throughput/delay }' >> figure.dat
done

#plot the graph
gnuplot figure5_put.plt
gnuplot figure6_delay.plt
gnuplot figure7_ratio.plt
